package com.qiaoyanqing.ximalaya.discovermodule.discover_adapter;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.ImageView;

import java.util.List;

/**
 * Created by Administrator on 2016/12/7.
 */

public class DiscoverRecommendFootVPadapter extends PagerAdapter{
    private List<ImageView>data;

    public DiscoverRecommendFootVPadapter(List<ImageView> data) {
        this.data = data;
    }

    @Override
    public int getCount() {
        return Integer.MAX_VALUE;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {

        return view==object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {

        if(data.size()==0){
            return null;
        }
        ImageView view=data.get(position%data.size());
        ViewParent parent=view.getParent();
        if (parent != null) {
            ViewGroup group= (ViewGroup) parent;
            group.removeView(view);
        }
        container.addView(view);
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        // super.destroyItem(container, position, object);

    }
}
